<?php namespace Zmsun\Util;use Zmsun\Filesystem\Folder;class HTMLSrc{public static function compressStr($str,$isFragment=false){$str=!$isFragment ? trim($str):preg_replace('/^\s+|\s+$/'," ",$str);if(!$str){return$str;}$newStr=preg_replace_callback('/<!--(.*)-->/Us',function($match){if($match[1]=='<![endif]'||preg_match('/^\[if\s+[^\]]+\]>/i',$match[1])){return$match[0];}else{return'';}},$str);return preg_replace('/\s+(?=\<|\>)|(?<=\<|\>)\s+/','',$newStr);}public static function compressFile($file,$saved=false){if((!$content=@file_get_contents($file))||!$content=static::compressStr($content)){return false;}if($saved){return file_put_contents($file,$content)? true:false;}return$content;}public static function compressDir($path){$paths=(array)$path;foreach($paths as$dir){$files=(new Folder($dir))->getFiles(array('htm','html'));foreach($files as$file){static::compressFile($file,true);}}}}?>